from framework.Function.ModbusBasicFunction.function import *


# action words

# 修改工位位置
def modify_station_pos(station_num, value):
    position_location_edit(station_num, value)
    assert abs(read_process_position(station_num) - value) < 0.001, " [工位位置错误:非预期的工位位置]"


# 多次读取小车停靠标记
def read_at_pos_signal(station_num):
    # 等待所有小车停下
    car_num = read_car_num()
    i = 1
    # 等待小车停下
    while i <= car_num:
        address_car_speed = 40008 + ((i - 1) * 40)
        if read_reg_float(address_car_speed) != 0:
            i = 1
            sleep(0.5)
            continue
        i = i + 1
    # 读取小车停靠标记
    address = 10002 + ((station_num - 1) * 30)
    while True:
        if read_reg_IntOrBool(address) != 1:
            sleep(0.5)
            continue
        else:
            break


# 读取工位位置
def Read_sation_pos(station_num):
    return read_station_position(station_num)


# 设置工位最大回退距离
def Set_max_back_dis_of_station(value):
    set_max_back_dis_of_station(value)


# 读取工位station_num当前停靠的系统小车号
def Read_station_car(station_num):
    return read_station_car(station_num)